package com.hb.trade.server.flow.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.flow.mapper.FlowTempFormMapper;
import com.hb.core.pojo.flow.entity.FlowTempForm;
import com.hb.core.pojo.flow.entity.FlowTempFormField;
import com.hb.core.pojo.flow.dto.FlowTempFormDTO;
import com.hb.trade.server.flow.service.FlowTempFormFieldService;
import com.hb.trade.server.flow.service.FlowTempFormService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 流程表单信息(模板) 服务实现类
 * </p>
 *
 * @author zhaojk
 * @since 2021-05-27
 */
@Service
public class FlowTempFormServiceImpl extends ServiceImpl<FlowTempFormMapper, FlowTempForm> implements FlowTempFormService {

    protected final FlowTempFormFieldService flowTempFormFieldService;

    public FlowTempFormServiceImpl(FlowTempFormFieldService flowTempFormFieldService) {
        this.flowTempFormFieldService = flowTempFormFieldService;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveFlowTempForm(FlowTempFormDTO formDto) {
        // 保存表单主表信息
        FlowTempForm tempForm = formDto.to(FlowTempForm.class);
        save(tempForm);
        // 保存表单字段
        List<FlowTempFormField> fields = formDto.getFormFields();
        flowTempFormFieldService.saveFormTempFields(tempForm.getId(), fields);
        return true;
    }
}
